<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.w3.org/1999/xhtml"
  exclude-result-prefixes="">

  <xsl:output method="html"/>

	<xsl:variable name="data" select="'../../data'"/>
  <xsl:variable name="projects" select="document(concat($data, '/pm/egw/pm_projects.content'))/*/*"/>
  <xsl:variable name="trackers" select="document(concat($data, '/pm/egw/tracker.content'))/*/*"/>
  <xsl:variable name="infologs"	select="document(concat($data, '/pm/egw/infolog.content'))/*/*"/>
	<xsl:variable name="links" select="document(concat($data, '/pm/egw/links.content'))/*/*"/>
  <xsl:variable name="elementLinks" select="$links[link_app2 = 'projectmanager']"/>
  <xsl:variable name="trackerLinks" select="$elementLinks[link_app1 = 'tracker']"/>
  <xsl:variable name="projectLinks"
    select="$links[link_app1 = 'projectmanager' and link_app2 = 'projectmanager']"/>

  <xsl:template match="/">
    <html>
      <body>
        <xsl:apply-templates select="$projects[empty(index-of($projectLinks/link_id2, pm_id))]">
          <xsl:with-param name="level" select="0"/>
        </xsl:apply-templates>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="egw_pm_projects">
    <xsl:param name="level"/>
    <xsl:for-each select="1 to $level">
      <xsl:text>----</xsl:text>
    </xsl:for-each>
    <xsl:text> </xsl:text>
    <xsl:value-of select="pm_id"/>: <xsl:value-of select="pm_number"/><br xmlns=""/>
    <xsl:apply-templates
      select="$projects[boolean(index-of($projectLinks[link_id1 = current()/pm_id]/link_id2, pm_id))]">
      <xsl:with-param name="level" select="$level + 1"/>
    </xsl:apply-templates>
    <xsl:apply-templates
      select="$trackers[boolean(index-of($trackerLinks[link_id2 = current()/pm_id]/link_id1, tr_id))]">
      <xsl:with-param name="level" select="$level + 1"/>
    </xsl:apply-templates>
  </xsl:template>
  
  <xsl:template match="egw_tracker">
    <xsl:param name="level"/>
    <xsl:for-each select="1 to $level">
      <xsl:text>----</xsl:text>
    </xsl:for-each>
    <xsl:text> </xsl:text>
    <xsl:value-of select="tr_summary"/> (<xsl:value-of select="tr_id"/>)<br xmlns=""/>
  </xsl:template>
  
</xsl:stylesheet>
